package ClientPackage;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import DSPackage.ClientDS;

public class Client {

    private Client() {
        
    }

    /**
     * Timeout will be standard timeout for RMI in this case
     */
    public static void main(String[] args) {

        boolean done = false;
        String response = null;
        
	String serverHost = (args.length < 2) ? null : args[0];
	String systemAppName = (args.length < 2) ? args[0] : args[1];
        
	try {
            while (!done) {
                Registry registry = LocateRegistry.getRegistry(serverHost, 2001);
                ClientDS clientDS = (ClientDS) registry.lookup("ClientDS");
                try {
                    response = clientDS.getApp(systemAppName);
                    done = true;
                } catch (Exception e) {
                    System.err.println("Client had exception connecting to"
                            + "Download server. Restarting.");
                    done = false;
                }

                System.out.println("\nServer answer: " + response + "\n"); 
            }
	} catch (Exception e) {
	    System.err.println("Client had exception: " + e.toString());
	}
    }
}